package com.sxf.core.aspect;


import com.sxf.auth.login.vo.LoginRes;

import java.util.Objects;

/**
 * @author villain
 */
public class UserThreadLocal {

    private static final ThreadLocal<LoginRes> USER_THREAD_LOCAL = new ThreadLocal<>();

    private UserThreadLocal() {}

    public static void set(LoginRes managerLoginVO) {
        USER_THREAD_LOCAL.set(managerLoginVO);
    }

    public static LoginRes get() {
        return USER_THREAD_LOCAL.get();
    }

    public static void remove() {
        USER_THREAD_LOCAL.remove();
    }

    public static String getUserId() {
        LoginRes loginRes = get();
        if (Objects.isNull(loginRes)){
            return null;
        }
        return loginRes.getPkUser();
    }
}
